const Mock = require('mockjs')

Mock.setup({
    timeout: '100-800'
})

let configArray = []

//遍历mock文件
const files = require.context('.', true, /\.js$/)
files.keys().forEach( key => {
    if(key==='./index.js'){
        return
    }
    configArray = configArray.concat(files(key).default)
});

//注册mock服务
configArray.forEach( item => {
    for(let [path, target]of Object.entries(item)){
        let protocol = path.split('|')
        Mock.mock(new RegExp('^'+protocol[1]), protocol[0], target)
    }
})

// const data = Mock.mock({
//     'receivedList|1-10':[{
//         'id|+1':1
//     }]
// })
// console.log(JSON.stringify(data,null,4))